{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Count Distinct Numbers on Board"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #hash-table #math #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #哈希表 #数学 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: distinctIntegers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #统计桌面上的不同数字"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个正整数 <code>n</code> ，开始时，它放在桌面上。在 <code>10<sup>9</sup></code> 天内，每天都要执行下述步骤：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>对于出现在桌面上的每个数字 <code>x</code> ，找出符合 <code>1 &lt;= i &lt;= n</code> 且满足 <code>x % i == 1</code> 的所有数字 <code>i</code> 。</li>\n",
    "\t<li>然后，将这些数字放在桌面上。</li>\n",
    "</ul>\n",
    "\n",
    "<p>返回在 <code>10<sup>9</sup></code> 天之后，出现在桌面上的 <strong>不同</strong> 整数的数目。</p>\n",
    "\n",
    "<p><strong>注意：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li>一旦数字放在桌面上，则会一直保留直到结束。</li>\n",
    "\t<li><code>%</code> 表示取余运算。例如，<code>14 % 3</code> 等于 <code>2</code> 。</li>\n",
    "</ul>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>n = 5\n",
    "<strong>输出：</strong>4\n",
    "<strong>解释：</strong>最开始，5 在桌面上。 \n",
    "第二天，2 和 4 也出现在桌面上，因为 5 % 2 == 1 且 5 % 4 == 1 。 \n",
    "再过一天 3 也出现在桌面上，因为 4 % 3 == 1 。 \n",
    "在十亿天结束时，桌面上的不同数字有 2 、3 、4 、5 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>n = 3 \n",
    "<strong>输出：</strong>2\n",
    "<strong>解释：</strong> \n",
    "因为 3 % 2 == 1 ，2 也出现在桌面上。 \n",
    "在十亿天结束时，桌面上的不同数字只有两个：2 和 3 。 \n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= n &lt;= 100</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [count-distinct-numbers-on-board](https://leetcode.cn/problems/count-distinct-numbers-on-board/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [count-distinct-numbers-on-board](https://leetcode.cn/problems/count-distinct-numbers-on-board/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['5', '3']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return len(range(2,n+1)) if n!=1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n != 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n>1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        if n == 1:\n",
    "            return 1\n",
    "        else:\n",
    "            return n - 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        res = set()\n",
    "    \n",
    "        gets(res,[n])\n",
    "        return len(res)\n",
    "\n",
    "def gets(res, q):\n",
    "    if not q:\n",
    "        return\n",
    "    l = []\n",
    "    for x in q:\n",
    "        res.add(x)\n",
    "        for i in range(1,x):\n",
    "            if i not in res and x%i == 1:\n",
    "                l.append(i)\n",
    "    gets(res,l)\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - (n != 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n-1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        if n == 1:\n",
    "            return 1\n",
    "        else: \n",
    "            return n-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n!=1 else  1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        if n == 1:\n",
    "            return 1\n",
    "        return n-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 1 else n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n != 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        if n == 1:\n",
    "            return 1\n",
    "        else:\n",
    "            return n-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return max(n-1, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        if n==1:\n",
    "            return 1\n",
    "        return n-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 1 else 1\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        if n==1:\n",
    "            return 1\n",
    "        return n-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        table = set([n])\n",
    "        remain = set(range(2, n))\n",
    "        while 1:\n",
    "            temp = set()\n",
    "            for r in remain:\n",
    "                flag = False\n",
    "                for t in table:\n",
    "                    if t % r == 1:\n",
    "                        table.add(r)\n",
    "                        flag = True\n",
    "                        break\n",
    "                if not flag:\n",
    "                    temp.add(r)\n",
    "            if len(remain) == len(temp):\n",
    "                return len(table)\n",
    "            remain = temp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        v = [0] * (n + 1)\n",
    "        v[n] = 1\n",
    "        while True:\n",
    "            flag = 0\n",
    "            for i in range(2, n + 1):\n",
    "                if not v[i]:\n",
    "                    continue\n",
    "                for j in range(2, i):\n",
    "                    if not v[j] and i % j == 1:\n",
    "                        v[j] = flag = 1\n",
    "            if not flag:\n",
    "                return sum(v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return 1 if n==1 else n-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - (n != 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n if n == 1 else n - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 2 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        if n==1: return 1\n",
    "        return n-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 1 else 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "         return n - 1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int: \n",
    "\n",
    "        if n > 1: \n",
    "            return n-1 \n",
    "        else: \n",
    "            return 1\n",
    "\n",
    "        '''\n",
    "        由于 n−1 一定满足要求，不断循环后，[2,n] 都会在桌面上，答案为 n−1 。\n",
    "        注意特判 n=1 的情况，此时答案为 1。\n",
    "\n",
    "        作者：灵茶山艾府\n",
    "        链接：https://leetcode.cn/problems/count-distinct-numbers-on-board/solutions/2080589/shu-xue-o1-jie-by-endlesscheng-hucn/\n",
    "\n",
    "        脑筋急转弯\n",
    "        当 n=1 时，答案就是 1。\n",
    "        当 n>1 时：\n",
    "        第一天，由于 n mod (n−1)=1，因此 (n−1) 会放在桌面上。\n",
    "        第二天，由于 (n−1) mod (n−2)=1，因此 (n−2) 会放在桌面上。\n",
    "        ...\n",
    "        这样最多 n 天就能把 2 到 n 都放在桌面上，远少于题目中要求的 10^9。\n",
    "        由于任何数  mod 1 都是 0 ，因此 1 永远不会放在桌面上。 因此答案就是 (n−1)。\n",
    "\n",
    "        复杂度 O(1)。\n",
    "\n",
    "        作者：TsReaper\n",
    "        链接：https://leetcode.cn/problems/count-distinct-numbers-on-board/solutions/2080593/by-tsreaper-0q4q/\n",
    "        '''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        l = [n]\n",
    "        t = 2\n",
    "        while n >= 1:\n",
    "            l_temp = []\n",
    "            for i in range(1,n):\n",
    "                if n % i  == 1:\n",
    "                    l_temp.append(i)\n",
    "            l.extend(l_temp)\n",
    "            t += 1\n",
    "            n -= 1\n",
    "        return len(set(l))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        # 用一个集合存放桌面上的所有数字\n",
    "        current_numbers = {n}\n",
    "        # 用一个集合存放已经访问过的数字，避免重复检查\n",
    "        visited = {n}\n",
    "        \n",
    "        # 对于每一天\n",
    "        for _ in range(10**9):\n",
    "            # 用一个新集合存放那一天新找到的数字\n",
    "            new_numbers = set()\n",
    "            # 遍历桌面上的每一个数字\n",
    "            for num in current_numbers:\n",
    "                # 寻找所有符合条件的 i\n",
    "                for i in range(1, n + 1):\n",
    "                    if num % i == 1:\n",
    "                        new_numbers.add(i)\n",
    "            \n",
    "            # 如果新的数字集合是空的，或者新的数字都已经被访问过，那么结束循环\n",
    "            if not new_numbers or all(num in visited for num in new_numbers):\n",
    "                break\n",
    "            \n",
    "            # 更新已访问的数字和桌面上的数字\n",
    "            visited |= new_numbers\n",
    "            current_numbers = new_numbers\n",
    "        \n",
    "        return len(visited)\n",
    "\n",
    "# 测试\n",
    "s = Solution()\n",
    "print(s.distinctIntegers(10))  # 一个示例输出\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n>1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        if n==1:\n",
    "            return 1\n",
    "        return n-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n-1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - (n > 1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 2 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        data_list = [n]\n",
    "        for count in range(0, n + 1):\n",
    "            for x in data_list:\n",
    "                for i in range(1, n + 1):\n",
    "                    if x % i == 1 and i not in data_list:\n",
    "                        data_list.append(i)\n",
    "\n",
    "        return len(data_list)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n>1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        if n == 1:\n",
    "            return 1\n",
    "        else:\n",
    "            return n-1\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n>1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return max(1, n - 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return 1 if n == 1 else n - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "    #    对于 x，每次都会把 x-1放到桌面上，% 余1\n",
    "        if n==1:\n",
    "            return 1\n",
    "        else:\n",
    "            return n-1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def distinctIntegers(self, n: int) -> int:\r\n",
    "        if n > 1:\r\n",
    "            return n-1\r\n",
    "        else:\r\n",
    "            return 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        # table = set([n])\n",
    "        # remain = set(range(2, n))\n",
    "        # while 1:\n",
    "        #     temp = set()\n",
    "        #     for r in remain:\n",
    "        #         flag = False\n",
    "        #         for t in table:\n",
    "        #             if t % r == 1:\n",
    "        #                 table.add(r)\n",
    "        #                 flag = True\n",
    "        #                 break\n",
    "        #         if not flag:\n",
    "        #             temp.add(r)\n",
    "        #     if len(remain) == len(temp):\n",
    "        #         return len(table)\n",
    "        #     remain = temp\n",
    "\n",
    "        # -----------------------------\n",
    "        return n - 1 if n > 1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n>1 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "\n",
    "        return n-1 if n!= 1 else 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 2 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n > 2 else 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n-1 if n > 1 else 1 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return max(1,n-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "\n",
    "        if n <= 2:\n",
    "            return 1\n",
    "        else:\n",
    "            return n - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return 1 if n == 1 else n - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        if n == 1:\n",
    "            return 1\n",
    "        return n - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        if n==1:\n",
    "            return 1\n",
    "        return n-1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def distinctIntegers(self, n: int) -> int:\n",
    "        return n - 1 if n != 1 else 1"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
